﻿using System;
using System.Collections.Generic;
using System.IO.IsolatedStorage;
using System.Linq;
using System.Text;


namespace LuyenThiVer03.UserData
{
    public class BieuDo
    {
        public double Score { get; set; }

        public string DeSo { get; set; }

        public int Stt { get; set; }

        public static void saveScore(string mon, BieuDo bieudo)
        {
            List<BieuDo> listCu = new List<BieuDo>();
            IsolatedStorageSettings iss = IsolatedStorageSettings.ApplicationSettings;

            listCu = loadScore(mon);
            if (listCu.Count < 7)
            {
                if (!iss.Contains(mon + listCu.Count))
                {
                    iss.Add(mon + listCu.Count, bieudo.Score + "-" + bieudo.DeSo);
                }
            }
            else
            {
                List<BieuDo> listMoi = new List<BieuDo>();
                for (int i = 1; i < 7; i++)
                {
                    BieuDo b = listCu[i];
                    listMoi.Add(b);
                }
                listMoi.Add(bieudo);

                int j = 0;
                foreach (BieuDo d in listMoi)
                {
                    try
                    {
                        iss.Add(mon + j, d.Score + "-" + d.DeSo);
                    }
                    catch (ArgumentException ae)
                    {
                        Console.WriteLine(ae.Message);
                    }
                }
            }
        }

        public static List<BieuDo> loadScore(string mon)
        {
            List<BieuDo> listBieuDo = new List<BieuDo>();
            IsolatedStorageSettings iss = IsolatedStorageSettings.ApplicationSettings;

            List<String> ls = new List<string>();

            for (int i = 0; i < 7; i++)
            {
                if (iss.Contains(mon + i))
                {
                    string a = iss[(mon + i)] as string;
                    ls.Add(a);
                }
            }

            foreach (string s in ls)
            {
                string[] g = s.Split('-');
                listBieuDo.Add(new BieuDo() { Score = System.Convert.ToDouble(g[0]), DeSo = "Đề " + g[1] });
            }

            return listBieuDo;
        }
       
    }
}
